<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 角色管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<link href="css/public.css" rel="stylesheet" type="text/css">
	<link href="css/index.css" rel="stylesheet" type="text/css">

	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/roleService.js"></script>
	
	<script type="text/javascript">
	
	function selectAllchild(object,id){
		for(var i=0;i<document.form1.elements.length;i++){
			if(document.form1.elements[i].type=="checkbox"){
				var e = document.form1.elements[i];
			    if (e.id == ("checkbox_fun_"+id)){
				   e.checked = eval("document.form1."+object+".checked");
				}
			}
		}
	}
	function CheckAll(form){
		for(var i=0;i<form.elements.length;i++){
			if(form.elements[i].type=="checkbox"){
			    if(form.elements[i].id!='chkall')
			    {
			       form.elements[i].checked = form.chkall.checked;
			    }
			}		
	    }
	}
	</script>
	
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<%@include file="/WEB-INF/jsp/include/left.jsp"%>	

	<!--right begin-->
    <div class="fl right">
 
 			<div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>角色快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>                
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/roleList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>角色名称：                </td>
                <td><input size="25" class="input" type="text" name="roleName" value="${searchCond.roleName}"/>
                </td>
                <td>
                	<input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" />
                </td>
              </tr>
            </table>
            </form>
      </div>
      
    		<!--人员分配 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>角色名称</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">                  
                  <tr>
                    <th width="4%" align="left"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="24%" align="left">ID</th>
                    <th width="24%" align="left">角色名称</th>
                    <th width="24%" align="left">角色描述</th>                                        
                    <th width="24%" align="left">操作</th>
                  </tr>
                </table>
              </div>
                <div class="list">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <c:forEach var="role" items="${roleList}">
                  <tr>
                    <td width="4%" align="left"><input type="checkbox" value="${role.id}" name="id" /></td>
                    <td width="24%" align="left">${role.id}</td>
                    <td width="24%" align="left">${role.roleName}</td>
                    <td width="24%" align="left">${role.detail}</td>
                    <td width="24%" align="left"><a href="javascript:;" onclick="delRole('${role.id}')">删除</a>
                    	|<a href="javascript:;" onclick="editRole('${role.id}')">修改</a>
                    	|<a href="javascript:;" onclick="editPermissions('${role.id}')">授权</a</td>
                  </tr>
                  </c:forEach>
                  <c:if test="${empty roleList}"><tr><td colspan="5" style="text-align:center">Sorry!没有相关记录哦！</td></tr></c:if>                  
              </table>
              </div>
            </div>
            <!--人员分配 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount} </strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
                </div>
                <div class="fr Operating">
                
                    <ul>
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addRole()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editRoles()"/></li>                        
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        
                    </ul>
                
                
                </div>
            </div>
 
            <!--统计 end-->
            
    </div>
	<!--right end-->
    <div id="win_temp" style="display:none">
	  	<div id="winCon_1"  >
			<table class="tabView" style="margin-top:5px">
				<tr><th width="100">角色名称：</th>
					<td><input type="text" name="roleName0" id="roleName0" value="" maxlength="100" style="width:200px"/>
						<input type="hidden" name="roleId0" id="roleId0" value="" />
						<input type="hidden" name="opacl" id="opacl" value="" /></td>
				</tr>
				<tr><th>角色说明：</th><td><textarea name="detail0" id="detail0" rows="4" cols="25"></textarea> </td></tr>
				<tr><td colspan="2" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitRole()"/></td></tr>
			</table>
		</div>
		<div id="winCon_2"  >
			<form:form method="post" name="form1">
			<table class="tabView" style="margin-top:5px">
				<tr><th width="150">角色名称：</th>
					<td><input type="text" name="roleName1" id="roleName1" value="" maxlength="100" style="width:200px" disabled />
						<input type="hidden" name="roleId1" id="roleId1" value="" />					
						<input type="hidden" name="acl1" id="acl1" value="" />
					</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_1"  name="checkbox_modul" value="1"/>系统管理：</th>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_2" name="checkbox_modul" value="2" />编码管理：</th>
					<td><input type="checkbox" id="checkbox_fun_21" name="checkbox_fun_2" value="1" />添加
						<input type="checkbox" id="checkbox_fun_22" name="checkbox_fun_2" value="2" />删除
						<input type="checkbox" id="checkbox_fun_23" name="checkbox_fun_2" value="3" />修改</td>
				</tr>				
				<tr>
					<th><input type="checkbox" id="checkbox_modul_3" name="checkbox_modul" value="3" />部门管理：</th>
					<td><input type="checkbox" id="checkbox_fun_31" name="checkbox_fun_3" value="1" />添加
						<input type="checkbox" id="checkbox_fun_32" name="checkbox_fun_3" value="2" />删除
						<input type="checkbox" id="checkbox_fun_33" name="checkbox_fun_3" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_4" name="checkbox_modul" value="4" />员工管理：</th>
					<td><input type="checkbox" id="checkbox_fun_41" name="checkbox_fun_4" value="1" />添加
						<input type="checkbox" id="checkbox_fun_42" name="checkbox_fun_4" value="2" />删除
						<input type="checkbox" id="checkbox_fun_43" name="checkbox_fun_4" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_5" name="checkbox_modul" value="roleList" />角色管理：</th>
					<td><input type="checkbox" id="checkbox_fun_51" name="checkbox_fun_roleList" value="1" />添加
						<input type="checkbox" id="checkbox_fun_52" name="checkbox_fun_roleList" value="2" />删除
						<input type="checkbox" id="checkbox_fun_53" name="checkbox_fun_roleList" value="3" />修改
						<input type="checkbox" id="checkbox_fun_54" name="checkbox_fun_roleList" value="4" />授权</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_6" name="checkbox_modul" value="6" />产品管理：</th>
					<td><input type="checkbox" id="checkbox_fun_61" name="checkbox_fun_6" value="1" />添加
						<input type="checkbox" id="checkbox_fun_62" name="checkbox_fun_6" value="2" />删除
						<input type="checkbox" id="checkbox_fun_63" name="checkbox_fun_6" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_7" name="checkbox_modul" value="7" />供应商管理：</th>
					<td><input type="checkbox" id="checkbox_fun_71" name="checkbox_fun_7" value="1" />添加
						<input type="checkbox" id="checkbox_fun_72" name="checkbox_fun_7" value="2" />删除
						<input type="checkbox" id="checkbox_fun_73" name="checkbox_fun_7" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_8" name="checkbox_modul" value="8" />供应商报价管理：</th>
					<td><input type="checkbox" id="checkbox_fun_81" name="checkbox_fun_8" value="1" />添加
						<input type="checkbox" id="checkbox_fun_82" name="checkbox_fun_8" value="2" />删除
						<input type="checkbox" id="checkbox_fun_83" name="checkbox_fun_8" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_9" name="checkbox_modul" value="9" />订单管理：</th>
					<td><input type="checkbox" id="checkbox_fun_91" name="checkbox_fun_9" value="1" />添加
						<input type="checkbox" id="checkbox_fun_92" name="checkbox_fun_9" value="2" />删除
						<input type="checkbox" id="checkbox_fun_93" name="checkbox_fun_9" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_10" name="checkbox_modul" value="10" />样品管理：</th>
					<td><input type="checkbox" id="checkbox_fun_101" name="checkbox_fun_10" value="1" />添加
						<input type="checkbox" id="checkbox_fun_102" name="checkbox_fun_10" value="2" />删除
						<input type="checkbox" id="checkbox_fun_103" name="checkbox_fun_10" value="3" />修改</td>
				</tr>
				<tr>
					<th><input type="checkbox" id="checkbox_modul_11" name="checkbox_modul" value="11" />通信录管理：</th>
					<td><input type="checkbox" id="checkbox_fun_111" name="checkbox_fun_11" value="1" />添加
						<input type="checkbox" id="checkbox_fun_112" name="checkbox_fun_11" value="2" />删除
						<input type="checkbox" id="checkbox_fun_113" name="checkbox_fun_11" value="3" />修改</td>
				</tr>
				<tr><td colspan="2" style="text-align:center;height:">
					<input type="checkbox" name="chkall" id="chkall" value="on" onclick="CheckAll(this.form)" /><label for="chkall" >全选</label>
					<input type="button" value=" 提 交 " class="btn1" onclick="submitPermissions()"/>
					</td></tr>
			</table>
			</form:form>
		</div>
  	</div>
  	
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>
<script  type="text/javascript">
	
	function delsellMultiple(){			
		var objs = document.getElementsByName("id");
		var ids='';	
		for(var i=0;i<objs.length;i++){
			if(objs[i].checked){
				ids+=objs[i].value+",";
			}
		}
		if(ids==''){
			alert("请先选择要操作的信息");
			return ;
		}
		ids = ids.substring(0,ids.length - 1);
		
		if(confirm("您确定要删除?")){
			if(ids == ""){
				alert("请先选择要删除的信息！");
				return false;
			}else{
				roleService.deleteRoleByIds(ids,{
					callback:function(f){alert("删除成功");reload();},
					exceptionHandler:function(message){alert("删除失败，请重试");},
					errorHander:function(err){}
				})
			}
		}
	}

	function editRoles(){
		var objs = document.getElementsByName("id");	
		var ids=0;
		var vas='';
		for(var i=0;i<objs.length;i++){
			if(objs[i].checked){
				ids++;
				vas=objs[i].value;			
			}
		}
		if(ids!=1){
			alert("请选择一条且只能选择一条信息进行编辑！");
			return ;
		}	
		if(vas==''){
			alert("请先选择要操作的信息");
			return ;
		}else{
			editRole(vas);
		}	
	}
	function addRole(){
		WIN.show('<font size=5>添加角色</font>',$('winCon_1'),{height:250});
	}
	
	function selectPermissions(acl){		
		if(acl==null){
			return ;
		}
		var mods = acl.split("|");
		var funs;
		var temp;
		for(var i=0;i<mods.length;i++){
			if(mods[i]!=null&&mods[i]!=''){				
				temp = mods[i].split(";");				
				if(temp!=null){
					document.getElementById("checkbox_modul_"+temp[0]).checked = true;
					if(temp[1]!=null&&temp[1]!=''){
						funs = temp[1].split(",");
						for(var j=0;j<funs.length;j++){		
							if(funs[j]!=null&&funs[j]!=''){
								//alert(temp[0]+funs[j]);
								document.getElementById("checkbox_fun_"+temp[0]+funs[j]).checked = true;
							}
						}
					}
				}			
			}			
		}		
	}
	
	function editPermissions(id){
		WIN.show('<font size=5>角色权限授权</font>',$('winCon_2'),{height:500});
		roleService.getRoleById(id,function(data){
			$('roleId1').value=data.id;
			$('roleName1').value=data.roleName;
			$('acl1').value=data.opAcl;
			selectPermissions(data.opAcl);			
		})
	}
	function editRole(id){
		WIN.show('<font size=5>修改角色</font>',$('winCon_1'),{height:250});
		roleService.getRoleById(id,function(data){
			$('roleId0').value=data.id;
			$('roleName0').value=data.roleName;
			$('detail0').value=data.detail;
			$('opacl').value=data.opAcl;	
		})
	}
	function delRole(id){
		if(confirm("确定删除 ？")){
			WIN.showpg();
			roleService.deleteRole(id,{
				callback:function(f){WIN.closepg();alert("删除成功");reload();},
				exceptionHandler:function(message){WIN.closepg();alert(message);alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
	
	function submitRole(){
		var dept={
			id:		$('roleId0').value,
			roleName:$('roleName0').value,
			detail:	$('detail0').value,
			opAcl: $('opacl').value
		}
		WIN.close();
		WIN.showpg();
		roleService.editRole(dept,{
			callback:function(f){WIN.closepg();alert("操作成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
			errorHander:function(err){}
		})
	}
	
	function submitPermissions(){
		var mods = document.getElementsByName("checkbox_modul");
		var funs;
		var acl = '';
		for(var i=0;i<mods.length;i++){
			if(mods[i].checked){
				acl+=mods[i].value+";";
				funs = document.getElementsByName("checkbox_fun_"+mods[i].value);
				for(var j=0;j<funs.length;j++){
					if(funs[j].checked){
						acl+=funs[j].value+",";
					}
				}
				acl+="|";
			}
		}
		if(acl==''){
			alert("请先选择要授权的信息");
			return ;
		}
		var id = $('roleId1').value;
		if(id==''){
			alert("请先选择要授权的角色信息");
			return ;
		}				
		WIN.close();
		WIN.showpg();
		roleService.updateRoleAcl(id,acl,{
			callback:function(f){WIN.closepg();alert("操作成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
			errorHander:function(err){}
		})
	}
	</script>
</body>
</html>
